package com.iplant.aps.serviceimpl.dao.aps;

import com.iplant.aps.service.mesenum.*;
import com.iplant.aps.service.po.OutResult;
import com.iplant.aps.service.po.Pagination;
import com.iplant.aps.service.po.ServiceResult;
import com.iplant.aps.service.po.aps.*;
import com.iplant.aps.service.po.bfc.BFCMessage;
import com.iplant.aps.service.po.bms.BMSEmployee;
import com.iplant.aps.service.po.excel.MyExcelSheet;
import com.iplant.aps.service.po.oms.OMSOrder;
import com.iplant.aps.service.utils.StringUtils;
import com.iplant.aps.serviceimpl.CoreServiceImpl;
import com.iplant.aps.serviceimpl.dao.BaseDAO;
import com.iplant.aps.serviceimpl.dao.oms.OMSOrderDAO;
import com.iplant.aps.serviceimpl.utils.MESServer;
import com.iplant.aps.serviceimpl.utils.aps.APSConstans;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;

import java.util.*;
import java.util.stream.Collectors;

public class APSTaskStepDAO extends BaseDAO {

    private static final Logger logger = LoggerFactory.getLogger(APSTaskStepDAO.class);

    private static APSTaskStepDAO Instance = null;

    private APSTaskStepDAO() {
        super();
    }

    public static APSTaskStepDAO getInstance() {
        if (Instance == null)
            Instance = new APSTaskStepDAO();
        return Instance;
    }

    /**
     * 添加或修改
     */
    public int Update(BMSEmployee wLoginUser, APSTaskStep wAPSTaskStep, OutResult<Integer> wErrorCode) {
        int wResult = 0;
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            if (wAPSTaskStep == null)
                return 0;

            String wSQL = "";
            if (wAPSTaskStep.getID() <= 0) {
                wSQL = StringUtils.Format("INSERT INTO {0}.aps_taskstep(OrderID,PartNo,TaskLineID,"
                        + "TaskPartID,WorkShopID,LineID,PartID,StepID,ShiftID,CreateTime,"
                        + "StartTime,EndTime,ReadyTime,Status,Active,ProductNo,MaterialNo,"
                        + "PlannerID,TaskText,WorkHour,OperatorList,IsDispatched,RemarkList,Remark,RealHour," +
                        "PlanStartTime,PlanEndTime,PartPointType,FQTY,MaterialNoNew) "
                        + "VALUES(:OrderID,:PartNo," + ":TaskLineID,:TaskPartID,:WorkShopID,:LineID,:PartID,"
                        + ":StepID,:ShiftID,now(),:StartTime,:EndTime,:ReadyTime,:Status,:Active,"
                        + ":ProductNo,:MaterialNo,:PlannerID,:TaskText,:WorkHour,:OperatorList,"
                        + ":IsDispatched,:RemarkList,:Remark,:RealHour,:PlanStartTime,:PlanEndTime," +
                        ":PartPointType,:FQTY,:MaterialNoNew);",
                        wInstance.Result);
            } else {
                wSQL = StringUtils.Format("UPDATE {0}.aps_taskstep SET OrderID = :OrderID,"
                        + "PartNo = :PartNo,TaskLineID = :TaskLineID,"
                        + "TaskPartID = :TaskPartID,WorkShopID = :WorkShopID,"
                        + "LineID = :LineID,PartID = :PartID,StepID = :StepID,"
                        + "ShiftID = :ShiftID,StartTime = :StartTime,EndTime = :EndTime,ReadyTime=:ReadyTime,"
                        + "Status = :Status,Active = :Active,ProductNo = :ProductNo,"
                        + "MaterialNo = :MaterialNo,PlannerID = :PlannerID,TaskText = :TaskText,"
                        + "WorkHour = :WorkHour,OperatorList=:OperatorList,"
                        + "IsDispatched=:IsDispatched,RemarkList=:RemarkList,"
                        + "Remark=:Remark,RealHour=:RealHour,PlanStartTime=:PlanStartTime," +
                        "PlanEndTime=:PlanEndTime,PartPointType=:PartPointType,FQTY=:FQTY," +
                        "MaterialNoNew=:MaterialNoNew WHERE ID = :ID;",
                        wInstance.Result);
            }

            wSQL = this.DMLChange(wSQL);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("ID", wAPSTaskStep.ID);
            wParamMap.put("OrderID", wAPSTaskStep.OrderID);
            wParamMap.put("PartNo", wAPSTaskStep.PartNo);
            wParamMap.put("TaskLineID", wAPSTaskStep.TaskLineID);
            wParamMap.put("TaskPartID", wAPSTaskStep.TaskPartID);
            wParamMap.put("WorkShopID", wAPSTaskStep.WorkShopID);
            wParamMap.put("LineID", wAPSTaskStep.LineID);
            wParamMap.put("PartID", wAPSTaskStep.PartID);
            wParamMap.put("StepID", wAPSTaskStep.StepID);
            wParamMap.put("ShiftID", wAPSTaskStep.ShiftID);
            wParamMap.put("StartTime", wAPSTaskStep.StartTime);
            wParamMap.put("EndTime", wAPSTaskStep.EndTime);
            wParamMap.put("ReadyTime", wAPSTaskStep.ReadyTime);
            wParamMap.put("Status", wAPSTaskStep.Status);
            wParamMap.put("Active", wAPSTaskStep.Active);
            wParamMap.put("ProductNo", wAPSTaskStep.ProductNo);
            wParamMap.put("MaterialNo", wAPSTaskStep.MaterialNo);
            wParamMap.put("PlannerID", wAPSTaskStep.PlanerID);
            wParamMap.put("TaskText", wAPSTaskStep.TaskText);
            wParamMap.put("WorkHour", wAPSTaskStep.WorkHour);
            wParamMap.put("IsDispatched", wAPSTaskStep.IsDispatched ? 1 : 0);
            wParamMap.put("OperatorList", StringUtils.Join(",", wAPSTaskStep.OperatorList));
            wParamMap.put("RemarkList", APSTaskRemark.ListToString(wAPSTaskStep.RemarkList));
            wParamMap.put("Remark", wAPSTaskStep.Remark.toString());
            wParamMap.put("RealHour", wAPSTaskStep.RealHour);
            wParamMap.put("PlanStartTime", wAPSTaskStep.PlanStartTime);
            wParamMap.put("PlanEndTime", wAPSTaskStep.PlanEndTime);
            wParamMap.put("PartPointType", wAPSTaskStep.PartPointType);
            wParamMap.put("FQTY", wAPSTaskStep.FQTY);
            wParamMap.put("MaterialNoNew", wAPSTaskStep.MaterialNoNew);

            KeyHolder keyHolder = new GeneratedKeyHolder();
            SqlParameterSource wSqlParameterSource = new MapSqlParameterSource(wParamMap);

            shrisJdbcTemplate.update(wSQL, wSqlParameterSource, keyHolder);

            if (wAPSTaskStep.getID() <= 0) {
                wResult = Objects.requireNonNull(keyHolder.getKey()).intValue();
                wAPSTaskStep.setID(wResult);
            } else {
                wResult = wAPSTaskStep.getID();
            }
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 删除集合
     */
    public ServiceResult<Integer> DeleteList(BMSEmployee wLoginUser, List<APSTaskStep> wList,
            OutResult<Integer> wErrorCode) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            if (wList == null || wList.size() <= 0)
                return wResult;

            List<String> wIDList = new ArrayList<>();
            for (APSTaskStep wItem : wList) {
                wIDList.add(String.valueOf(wItem.ID));
            }
            String wSql = StringUtils.Format("delete from {1}.aps_taskstep WHERE ID IN({0}) ;",
                    String.join(",", wIDList), wInstance.Result);
            this.ExecuteSqlTransaction(wSql);
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 查单条
     */
    public APSTaskStep SelectByID(BMSEmployee wLoginUser, int wID, OutResult<Integer> wErrorCode) {
        APSTaskStep wResult = new APSTaskStep();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            List<APSTaskStep> wList = SelectList(wLoginUser, wID, -1, -1, -1, -1, -1, -1, -1, -1, -1, null, null, null,
                    null, wErrorCode);
            if (wList == null || wList.size() != 1)
                return wResult;
            wResult = wList.get(0);
        } catch (Exception e) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(e.toString());
        }
        return wResult;
    }

    /**
     * 条件查询集合
     */
    public List<APSTaskStep> SelectList(BMSEmployee wLoginUser, int wID, int wOrderID, int wTaskLineID, int wTaskPartID,
            int wWorkShopID, int wLineID, int wPartID, int wStepID, int wShiftID,
            int wActive,
            List<Integer> wStateIDList, Calendar wStartTime, Calendar wEndTime,
            List<Integer> wPartIDList,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResultList = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            if (wStateIDList == null)
                wStateIDList = new ArrayList<>();

            if (wPartIDList == null) {
                wPartIDList = new ArrayList<>();
            }

            Calendar wBaseTime = Calendar.getInstance();
            wBaseTime.set(2000, 0, 1);
            if (wStartTime == null) {
                wStartTime = wBaseTime;
            }
            if (wEndTime == null) {
                wEndTime = wBaseTime;
            }

            String wSQL = StringUtils.Format("SELECT t1.*,t2.OrderNo,t3.MaterialName,t4.WorkAreaID,t5.Name " +
                    "WorkAreaName,t6.CustomerName FROM {0}.aps_taskstep t1" +
                    " left join {0}.oms_order t2 on t1.OrderID=t2.ID " +
                    " left join {0}.mss_material t3 on t1.MaterialNoNew=t3.MaterialNo "
                    + " left join {0}.lfs_workareastation t4 on t1.PartID=t4.StationID "
                    + " left join {0}.bms_department t5 on t4.WorkAreaID=t5.ID "
                    + " left join {0}.crm_customer t6 on t2.BureauSectionID=t6.ID "
                    + "WHERE t1.OrderID=t2.ID "
                    + "and ( :wID <= 0 or :wID = t1.ID ) " + "and ( :wOrderID <= 0 or :wOrderID = t1.OrderID ) "
                    + "and ( :wTaskLineID <= 0 or :wTaskLineID = t1.TaskLineID ) "
                    + "and ( :wTaskPartID <= 0 or :wTaskPartID = t1.TaskPartID ) "
                    + "and ( :wWorkShopID <= 0 or :wWorkShopID = t1.WorkShopID ) "
                    + "and ( :wLineID <= 0 or :wLineID = t1.LineID ) "
                    + "and ( :wPartID <= 0 or :wPartID = t1.PartID ) "
                    + "and ( :wStepID <= 0 or :wStepID = t1.StepID ) "
                    + "and ( :wShiftID <= 0 or :wShiftID = t1.ShiftID ) "
                    + "and ( :wActive <= 0 or :wActive = t1.Active ) "
                    + "and ( :wStartTime <= str_to_date(''2010-01-01'', ''%Y-%m-%d'') or :wStartTime <= t1" +
                    ".CreateTime) "
                    + "and ( :wEndTime <= str_to_date(''2010-01-01'', ''%Y-%m-%d'') or :wEndTime >= t1" +
                    ".CreateTime) "
                    + "and ( :wPart = '''' or t1.PartID in ({2})) "
                    + "and ( :wStatus is null or :wStatus = '''' or t1.Status in ({1}));", wInstance.Result,
                    wStateIDList.size() > 0 ? StringUtils.Join(",", wStateIDList) : "0",
                    wPartIDList.size() > 0 ? StringUtils.Join(",", wPartIDList) : "0");

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("wID", wID);
            wParamMap.put("wOrderID", wOrderID);
            wParamMap.put("wTaskLineID", wTaskLineID);
            wParamMap.put("wTaskPartID", wTaskPartID);
            wParamMap.put("wWorkShopID", wWorkShopID);
            wParamMap.put("wLineID", wLineID);
            wParamMap.put("wPartID", wPartID);
            wParamMap.put("wStepID", wStepID);
            wParamMap.put("wShiftID", wShiftID);
            wParamMap.put("wActive", wActive);
            wParamMap.put("wStatus", StringUtils.Join(",", wStateIDList));
            wParamMap.put("wStartTime", wStartTime);
            wParamMap.put("wEndTime", wEndTime);
            wParamMap.put("wPart", StringUtils.Join(",", wPartIDList));

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            SetValue(wResultList, wQueryResult);
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResultList;
    }

    /**
     * 条件查询集合
     */
    public List<APSTaskStep> SelectListByPage(BMSEmployee wLoginUser, int wID, int wOrderID, int wTaskLineID,
            int wTaskPartID,
            int wWorkShopID, int wLineID, int wPartID, int wStepID, int wShiftID,
            int wActive,
            List<Integer> wStateIDList, Calendar wStartTime, Calendar wEndTime,
            List<Integer> wPartIDList, String wDutyPerson, Pagination wPagination,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResultList = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            if (wStateIDList == null)
                wStateIDList = new ArrayList<>();

            if (wPartIDList == null) {
                wPartIDList = new ArrayList<>();
            }

            Calendar wBaseTime = Calendar.getInstance();
            wBaseTime.set(2000, 0, 1);
            if (wStartTime == null) {
                wStartTime = wBaseTime;
            }
            if (wEndTime == null) {
                wEndTime = wBaseTime;
            }

            String wSQL = StringUtils.Format("SELECT distinct t1.*,t2.OrderNo,t3.MaterialName,t4.WorkAreaID,t5.Name " +
                    "WorkAreaName,t6.CustomerName FROM {0}.aps_taskstep t1" +
                    " left join {0}.oms_order t2 on t1.OrderID=t2.ID " +
                    " left join {0}.mss_material t3 on t1.MaterialNoNew=t3.MaterialNo "
                    + " left join {0}.lfs_workareastation t4 on t1.PartID=t4.StationID "
                    + " left join {0}.bms_department t5 on t4.WorkAreaID=t5.ID "
                    + " left join {0}.crm_customer t6 on t2.BureauSectionID=t6.ID "
                    + " left join {0}.sfc_taskstep t7 on t1.ID=t7.TaskStepID "
                    + " left join {0}.mbs_user t8 on t7.OperatorID=t8.ID "
                    + "WHERE t1.OrderID=t2.ID "
                    + "and ( :wID <= 0 or :wID = t1.ID ) "
                    + "and ( :wOrderID <= 0 or :wOrderID = t1.OrderID ) "
                    + "and ( :wTaskLineID <= 0 or :wTaskLineID = t1.TaskLineID ) "
                    + "and ( :wTaskPartID <= 0 or :wTaskPartID = t1.TaskPartID ) "
                    + "and ( :wWorkShopID <= 0 or :wWorkShopID = t1.WorkShopID ) "
                    + "and ( :wLineID <= 0 or :wLineID = t1.LineID ) "
                    + "and ( :wPartID <= 0 or :wPartID = t1.PartID ) "
                    + "and ( :wStepID <= 0 or :wStepID = t1.StepID ) "
                    + "and ( :wShiftID <= 0 or :wShiftID = t1.ShiftID ) "
                    + "and ( :wActive <= 0 or :wActive = t1.Active ) "
                    + "and ( :wDutyPerson is null or :wDutyPerson = '''' or t8.Name like ''%{3}%'') "
                    + "and ( :wStartTime <= str_to_date(''2010-01-01'', ''%Y-%m-%d'') or :wStartTime <= t1" +
                    ".CreateTime) "
                    + "and ( :wEndTime <= str_to_date(''2010-01-01'', ''%Y-%m-%d'') or :wEndTime >= t1" +
                    ".CreateTime) "
                    + "and ( :wPart = '''' or t1.PartID in ({2})) "
                    + "and ( :wStatus is null or :wStatus = '''' or t1.Status in ({1})) ", wInstance.Result,
                    wStateIDList.size() > 0 ? StringUtils.Join(",", wStateIDList) : "0",
                    wPartIDList.size() > 0 ? StringUtils.Join(",", wPartIDList) : "0", wDutyPerson);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("wID", wID);
            wParamMap.put("wOrderID", wOrderID);
            wParamMap.put("wTaskLineID", wTaskLineID);
            wParamMap.put("wTaskPartID", wTaskPartID);
            wParamMap.put("wWorkShopID", wWorkShopID);
            wParamMap.put("wLineID", wLineID);
            wParamMap.put("wPartID", wPartID);
            wParamMap.put("wStepID", wStepID);
            wParamMap.put("wShiftID", wShiftID);
            wParamMap.put("wActive", wActive);
            wParamMap.put("wStatus", StringUtils.Join(",", wStateIDList));
            wParamMap.put("wStartTime", wStartTime);
            wParamMap.put("wEndTime", wEndTime);
            wParamMap.put("wPart", StringUtils.Join(",", wPartIDList));
            wParamMap.put("wDutyPerson", wDutyPerson);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap, wPagination);

            SetValue(wResultList, wQueryResult);
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResultList;
    }

    /**
     * 条件查询集合
     */
    public List<APSTaskStep> SelectQTList(BMSEmployee wLoginUser, Calendar wStartTime, Calendar wEndTime,
            List<Integer> wStateIDList, List<Integer> wPartIDList,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResultList = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            Calendar wBaseTime = Calendar.getInstance();
            wBaseTime.set(2000, 0, 1);
            if (wStartTime == null) {
                wStartTime = wBaseTime;
            }
            if (wEndTime == null) {
                wEndTime = wBaseTime;
            }

            if (wStateIDList == null) {
                wStateIDList = new ArrayList<>();
            }

            if (wPartIDList == null) {
                wPartIDList = new ArrayList<>();
            }

            String wSQL = StringUtils.Format("SELECT t1.*,t2.OrderNo "
                    + "FROM {0}.aps_taskstep t1,{0}.oms_order t2  WHERE t1.OrderID=t2.ID "
                    + "and ( :wStartTime <= str_to_date(''2010-01-01'', ''%Y-%m-%d'') or :wStartTime <= t1" +
                    ".EndTime) "
                    + "and ( :wEndTime <= str_to_date(''2010-01-01'', ''%Y-%m-%d'') or :wEndTime >= t1" +
                    ".StartTime) "
                    + "and ( :wPart is null or :wPart = '''' or t1.PartID in ({2})) "
                    + "and ( :wStatus is null or :wStatus = '''' or t1.Status in ({1}));", wInstance.Result,
                    wStateIDList.size() > 0 ? StringUtils.Join(",", wStateIDList) : "0",
                    wPartIDList.size() > 0 ? StringUtils.Join(",", wPartIDList) : "0");

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("wStatus", StringUtils.Join(",", wStateIDList));
            wParamMap.put("wStartTime", wStartTime);
            wParamMap.put("wEndTime", wEndTime);
            wParamMap.put("wPart", StringUtils.Join(",", wPartIDList));

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            SetValue(wResultList, wQueryResult);
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResultList;
    }

    /**
     * 条件查询集合(时间必给)
     */
    public List<APSTaskStep> SelectListByTime(BMSEmployee wLoginUser, Calendar wStartTime, Calendar wEndTime,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResultList = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            Calendar wBaseTime = Calendar.getInstance();
            wBaseTime.set(2000, 0, 1);
            if (wStartTime == null) {
                wStartTime = wBaseTime;
            }
            if (wEndTime == null) {
                wEndTime = wBaseTime;
            }

            String wSQL = StringUtils.Format("SELECT t1.*,t2.OrderNo FROM {0}.aps_taskstep t1,{0}.oms_order t2  "
                    + "WHERE t1.OrderID=t2.ID and ((:wStartTime <= t1.CreateTime and t1.CreateTime <= :wEndTime) "
                    + "or (:wStartTime <= t1.EndTime  and  :wEndTime >= t1.StartTime) );", wInstance.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("wStartTime", wStartTime);
            wParamMap.put("wEndTime", wEndTime);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            SetValue(wResultList, wQueryResult);
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResultList;
    }

    /**
     * 条件查询审批过的任务
     *
     * @param wLoginUser 登录信息
     * @return 工序任务集合
     */
    public List<APSTaskStep> SelectAuditList(BMSEmployee wLoginUser, Calendar wStartTime, Calendar wEndTime,
            int wAuditID, OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResultList = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            Calendar wBaseTime = Calendar.getInstance();
            wBaseTime.set(2000, 0, 1);
            if (wStartTime == null) {
                wStartTime = wBaseTime;
            }
            if (wEndTime == null) {
                wEndTime = wBaseTime;
            }

            String wSQL = StringUtils.Format(
                    "SELECT t1.*,t2.OrderNo FROM {0}.aps_taskstep t1,{0}.oms_order t2 , {2}.bfc_auditaction t3 "
                            + "where t1.OrderID=t2.ID and t3.TaskID=t1.ID and t3.EventModule={1} "
                            + "and :wStartTime<= t3.AuditorTime " + "and t3.AuditorTime<=:wEndTime "
                            + "and t3.AuditorID=:wAuditID;",
                    wInstance.Result, BPMEventModule.SCDayAudit.getValue(), wInstance1.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("wStartTime", wStartTime);
            wParamMap.put("wEndTime", wEndTime);
            wParamMap.put("wAuditID", wAuditID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            SetValue(wResultList, wQueryResult);
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResultList;
    }

    /**
     * 检查当日是否可制定日计划
     */
    public String CheckShiftDate(BMSEmployee wLoginUser, Calendar wShiftDate, OutResult<Integer> wErrorCode) {
        String wResult = "";
        try {
            if (wShiftDate == null) {
                wResult = "提示：参数错误!";
                return wResult;
            }

            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            int wShiftID = MESServer.MES_QueryShiftID(wLoginUser.CompanyID, wShiftDate, APSShiftPeriod.Day,
                    FMCShiftLevel.Day, 0);

            int wTShiftID = MESServer.MES_QueryShiftID(wLoginUser.CompanyID, Calendar.getInstance(), APSShiftPeriod.Day,
                    FMCShiftLevel.Day, 0);

            if (wShiftID < wTShiftID) {
                wResult = "提示：生成日期有误";
                return wResult;
            }

            String wSQL = StringUtils.Format("SELECT COUNT(*) as Number FROM {0}.aps_taskstep where ShiftID > {1};",
                    wInstance.Result, wShiftID);

            Map<String, Object> wParamMap = new HashMap<>();

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            int wNumber = 0;
            for (Map<String, Object> wReader : wQueryResult) {
                wNumber = StringUtils.parseInt(wReader.get("Number"));
                break;
            }

            if (wNumber > 0) {
                wResult = StringUtils.Format("提示：未来日计划已制定，无法制定【{0}】日计划!", wShiftID);
                return wResult;
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 条件查询集合
     */
    public List<APSTaskStep> SelectListByTaskPartIDList(BMSEmployee wLoginUser, List<Integer> wTaskPartIDList,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResultList = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            if (wTaskPartIDList == null) {
                wTaskPartIDList = new ArrayList<>();
            }

            String wSQL = StringUtils.Format(
                    "SELECT t1.*,t2.OrderNo " + "FROM {0}.aps_taskstep t1,{0}.oms_order t2  WHERE t1.OrderID=t2.ID "
                            + "and t1.Active=1 "
                            + "and ( :wTaskPartIDList is null or :wTaskPartIDList = '''' or t1.TaskPartID in ({1}));",
                    wInstance.Result, wTaskPartIDList.size() > 0 ? StringUtils.Join(",", wTaskPartIDList) : "0");

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("wTaskPartIDList", StringUtils.Join(",", wTaskPartIDList));

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            SetValue(wResultList, wQueryResult);
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResultList;
    }

    private void SetValue(List<APSTaskStep> wResultList, List<Map<String, Object>> wQueryResult) {
        try {
            for (Map<String, Object> wReader : wQueryResult) {
                APSTaskStep wItem = new APSTaskStep();

                wItem.ID = StringUtils.parseInt(wReader.get("ID"));
                wItem.OrderID = StringUtils.parseInt(wReader.get("OrderID"));
                wItem.PartNo = StringUtils.parseString(wReader.get("PartNo"));
                wItem.TaskLineID = StringUtils.parseInt(wReader.get("TaskLineID"));
                wItem.TaskPartID = StringUtils.parseInt(wReader.get("TaskPartID"));
                wItem.WorkShopID = StringUtils.parseInt(wReader.get("WorkShopID"));
                wItem.LineID = StringUtils.parseInt(wReader.get("LineID"));
                wItem.PartID = StringUtils.parseInt(wReader.get("PartID"));
                wItem.StepID = StringUtils.parseInt(wReader.get("StepID"));
                wItem.ShiftID = StringUtils.parseInt(wReader.get("ShiftID"));
                wItem.StartTime = StringUtils.parseCalendar(wReader.get("StartTime"));
                wItem.CreateTime = StringUtils.parseCalendar(wReader.get("CreateTime"));
                wItem.EndTime = StringUtils.parseCalendar(wReader.get("EndTime"));
                wItem.ReadyTime = StringUtils.parseCalendar(wReader.get("ReadyTime"));
                wItem.PlanStartTime = StringUtils.parseCalendar(wReader.get("PlanStartTime"));
                wItem.PlanEndTime = StringUtils.parseCalendar(wReader.get("PlanEndTime"));
                wItem.Status = StringUtils.parseInt(wReader.get("Status"));
                wItem.Active = StringUtils.parseInt(wReader.get("Active"));
                wItem.ProductNo = StringUtils.parseString(wReader.get("ProductNo"));
                wItem.MaterialNo = StringUtils.parseString(wReader.get("MaterialNo"));
                wItem.MaterialName = StringUtils.parseString(wReader.get("MaterialName"));
                wItem.PlanerID = StringUtils.parseInt(wReader.get("PlannerID"));
                wItem.PlanerName = APSConstans.GetBMSEmployeeName(wItem.PlanerID);
                wItem.TaskText = StringUtils.parseString(wReader.get("TaskText"));
                wItem.WorkHour = StringUtils.parseDouble(wReader.get("WorkHour"));
                wItem.RealHour = StringUtils.parseDouble(wReader.get("RealHour"));
                wItem.OperatorList = StringUtils
                        .parseIntList(StringUtils.parseString(wReader.get("OperatorList")).split("[,;]"));
                wItem.IsDispatched = StringUtils.parseInt(wReader.get("IsDispatched")) == 1;
                wItem.RemarkList = APSTaskRemark.StringToList(StringUtils.parseString(wReader.get("RemarkList")));
                wItem.Remark = new APSTaskRemark(StringUtils.parseString(wReader.get("Remark")));
                if (wReader.containsKey("WorkAreaID")) {
                    wItem.AreaID = StringUtils.parseInt(wReader.get("WorkAreaID"));
                    wItem.AreaName = StringUtils.parseString(wReader.get("WorkAreaName"));
                }
                if (wReader.containsKey("CustomerName")) {
                    wItem.CustomerName = StringUtils.parseString(wReader.get("CustomerName"));
                }
                if (wReader.containsKey("OrderStatus")) {
                    wItem.OrderStatus = StringUtils.parseInt(wReader.get("OrderStatus"));
                }

                wItem.LineName = APSConstans.GetFMCLineName(wItem.LineID);
                wItem.PartName = APSConstans.GetFPCPartName(wItem.PartID);
                wItem.StepName = APSConstans.GetFPCPartPointName(wItem.StepID);

                wItem.OrderNo = StringUtils.parseString(wReader.get("OrderNo"));
                wItem.PartPointType = StringUtils.parseInt(wReader.get("PartPointType"));
                wItem.PartPointTypeText = FPCPartPointType.getEnumType(wItem.PartPointType).getLable();
                wItem.FQTY = StringUtils.parseDouble(wReader.get("FQTY"));
                wItem.MaterialNoNew = StringUtils.parseString(wReader.get("MaterialNoNew"));

                wItem.Operators = APSConstans.GetBMSEmployeeName(wItem.OperatorList);

                wResultList.add(wItem);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
    }

    /**
     * 批量激活或禁用
     */
    public ServiceResult<Integer> Active(BMSEmployee wLoginUser, List<Integer> wIDList, int wActive,
            OutResult<Integer> wErrorCode) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            if (wIDList == null || wIDList.size() <= 0)
                return wResult;
            for (Integer wItem : wIDList) {
                APSTaskStep wAPSTaskStep = SelectByID(wLoginUser, wItem, wErrorCode);
                if (wAPSTaskStep == null || wAPSTaskStep.ID <= 0)
                    continue;
                // 只有激活的才能禁用
                if (wActive == 2 && wAPSTaskStep.Active != 1) {
                    wErrorCode.set(MESException.Logic.getValue());
                    return wResult;
                }
                wAPSTaskStep.Active = wActive;
                long wID = Update(wLoginUser, wAPSTaskStep, wErrorCode);
                if (wID <= 0)
                    break;
            }
        } catch (Exception e) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(e.toString());
        }
        return wResult;
    }

    /**
     * 通过ID集合获取集合
     */
    public List<APSTaskStep> SelectListByIDList(BMSEmployee wLoginUser, List<Integer> wIDList,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResultList = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            if (wIDList == null) {
                wIDList = new ArrayList<>();
            }

            String wSQL = StringUtils.Format(
                    "SELECT t1.*,t2.OrderNo,t3.MaterialName,t4.CustomerName FROM {0}.aps_taskstep t1" +
                            " left join {0}.oms_order t2 on t1.OrderID=t2.ID " +
                            "  left join {0}.mss_material t3 on t1.MaterialNoNew=t3.MaterialNo  " +
                            " left join {0}.crm_customer t4 on t2.BureauSectionID=t4.ID " +
                            "WHERE ( :wIDs is null or :wIDs = '''' or t1.ID in ({1}));",
                    wInstance.Result, wIDList.size() > 0 ? StringUtils.Join(",", wIDList) : "0");

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("wIDs", StringUtils.Join(",", wIDList));

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            SetValue(wResultList, wQueryResult);
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResultList;
    }

    /**
     * 重置工序任务到派工
     */
    public Integer ReSet(BMSEmployee wLoginUser, int wAPSTaskStepID, OutResult<Integer> wErrorCode) {
        Integer wResult = 0;
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance2 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.EXC,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance2.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSql = StringUtils.Format(
                    "update {1}.aps_taskstep set IsDispatched=0,OperatorList='''' where ID={0}; "
                            + "delete from {2}.sfc_loginstation where SFCTaskStepID in( "
                            + "	select ID from {1}.sfc_taskstep where TaskStepID= {0} " + ") and ID>0; "
                            + "delete from {1}.sfc_taskstep where TaskStepID= {0} and ID>0; "
                            + "delete from {3}.ipt_value where TaskID in( "
                            + "	select ID from {2}.sfc_taskipt where TaskStepID= {0} " + ") and ID>0; "
                            + "delete FROM {2}.sfc_taskipt where TaskStepID= {0} and ID>0;",
                    String.valueOf(wAPSTaskStepID), wInstance.Result, wInstance1.Result, wInstance2.Result);
            this.ExecuteSqlTransaction(wSql);
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 通过登录人、时间段查询终检和出厂检工序任务
     */
    public List<APSTaskStep> SelectFinalAndOutList(BMSEmployee wLoginUser, Calendar wStartTime, Calendar wEndTime,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResultList = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            String wSQL = StringUtils.Format(
                    "SELECT t1.*,t5.Status OrderStatus FROM {0}.aps_taskstep t1,{1}.fpc_part t2," + "{1}" +
                            ".bms_workcharge t3,{1}.mbs_user t4,{1}.oms_order t5 "
                            + "where t1.OrderID=t5.ID and t1.Active=1 and t4.ID=:LoginID and t4.DepartmentID=t3" +
                            ".ClassID and t3.StationID=t2.ID "
                            + "and t2.PartType in(3,4) and t1.PartID=t2.ID "
                            + "and ((:StartTime<t1.EndTime and :EndTime>t1.StartTime "
                            + "and t1.Status in(5)) or (t1.Status in(2,4)));",
                    wInstance.Result, wInstance1.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("LoginID", wLoginUser.ID);
            wParamMap.put("StartTime", wStartTime);
            wParamMap.put("EndTime", wEndTime);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            SetValue(wResultList, wQueryResult);
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResultList;
    }

    /**
     * 根据订单、工位、车号查询工序任务
     */
    public List<APSTaskStep> SelectListByOrder(BMSEmployee wLoginUser, int wOrderID, int wPartID, String wPartNo,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResultList = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            String wSQL = StringUtils.Format(
                    "SELECT t1.*,t2.OrderNo,t3.MaterialName,t4.CustomerName FROM {0}.aps_taskstep t1"
                            + " left join {0}.oms_order t2 on t1.OrderID=t2.ID "
                            + " left join {0}.mss_material t3 on t1.MaterialNoNew=t3.MaterialNo "
                            + " left join {0}.crm_customer t4 on t2.BureauSectionID=t4.ID "
                            + "WHERE t1.OrderID=t2.ID "
                            + "and ( :wOrderID <= 0 or :wOrderID = t1.OrderID ) "
                            + "and ( :wPartID <= 0 or :wPartID = t1.PartID ) "
                            + "and ( :wPartNo is null or :wPartNo = '''' or t1.PartNo =:wPartNo);",
                    wInstance.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("wOrderID", wOrderID);
            wParamMap.put("wPartID", wPartID);
            wParamMap.put("wPartNo", wPartNo);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            SetValue(wResultList, wQueryResult);
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResultList;
    }

    /**
     * 根据人员ID判断此人是否能做此工序任务
     */
    public boolean JudgeCanDo(BMSEmployee wLoginUser, int wAPSTaskStepID, int wPersonID,
            OutResult<Integer> wErrorCode) {
        boolean wResult = false;
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return false;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return false;
            }

            String wSQL = StringUtils.Format(
                    "select (SELECT count(*) FROM {0}.sch_secondmentapply "
                            + "where PersonID=:PersonID and Status=:Status and StartTime<now() and now()< EndTime "
                            + "and OldClassID in((SELECT ClassID FROM {1}.bms_workcharge t1,{0}.aps_taskstep t2 "
                            + "where t1.StationID=t2.PartID and t2.ID=:APSTaskStepID and t1.Active=1))) as t1,"
                            + "(SELECT count(*) FROM {0}.sch_secondmentapply where PersonID=:PersonID "
                            + "and Status=:Status and StartTime<now() and now()< EndTime and NewClassID in"
                            + "((SELECT ClassID FROM {1}.bms_workcharge t1,{0}.aps_taskstep t2 "
                            + "where t1.StationID=t2.PartID and t2.ID=:APSTaskStepID and t1.Active=1))) as t2,"
                            + "(SELECT count(*) FROM {1}.mbs_user where ID=:PersonID and DepartmentID in "
                            + "(SELECT ClassID FROM {1}.bms_workcharge t1,{0}.aps_taskstep t2 "
                            + "where t1.StationID=t2.PartID and t2.ID=:APSTaskStepID and t1.Active=1)) as t3;",
                    wInstance.Result, wInstance1.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("Status", 20);
            wParamMap.put("APSTaskStepID", wAPSTaskStepID);
            wParamMap.put("PersonID", wPersonID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wMap : wQueryResult) {
                int wT1 = StringUtils.parseInt(wMap.get("t1"));
                int wT2 = StringUtils.parseInt(wMap.get("t2"));
                int wT3 = StringUtils.parseInt(wMap.get("t3"));
                wResult = wT1 > 0 || wT2 > 0 || wT3 > 0;
                return wResult;
            }
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return false;
    }

    /**
     * 工序任务ID获取派工人和执行班组
     */
    public APSTaskStepInfo QueryDispatchInfo(BMSEmployee wLoginUser, int wAPSTaskStepID,
            OutResult<Integer> wErrorCode) {
        APSTaskStepInfo wResult = new APSTaskStepInfo();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "SELECT t2.Name as Dispacher,t3.Name as ClassName FROM {0}.sfc_taskstep t1,"
                            + "{1}.mbs_user t2,{1}.bms_department t3 where t1.MonitorID=t2.ID "
                            + "and t2.DepartmentID=t3.ID and t1.TaskStepID=:TaskStepID group by t2.Name;",
                    wInstance.Result, wInstance1.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("TaskStepID", wAPSTaskStepID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wMap : wQueryResult) {
                String wClassName = StringUtils.parseString(wMap.get("ClassName"));
                String wDispacher = StringUtils.parseString(wMap.get("Dispacher"));
                wResult.ClassName = wClassName;
                wResult.Dispather = wDispacher;
                return wResult;
            }
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 根据时间段和班次获取工序详情
     */
    public List<APSTaskStepInfo> QueryAPSTaskStepInfoList(BMSEmployee wLoginUser, Calendar wStartTime,
            Calendar wEndTime, List<Integer> wClassIDList,
            List<Integer> wPartIDList, List<Integer> wStatusList,
            int wIsDispatched, OutResult<Integer> wErrorCode) {
        List<APSTaskStepInfo> wResult = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            Calendar wBaseTime = Calendar.getInstance();
            wBaseTime.set(2000, 0, 1, 0, 0, 0);
            if (wStartTime == null) {
                wStartTime = wBaseTime;
            }
            if (wEndTime == null) {
                wEndTime = wBaseTime;
            }
            if (wStartTime.compareTo(wEndTime) > 0) {
                return wResult;
            }

            if (wClassIDList == null) {
                wClassIDList = new ArrayList<>();
            }
            if (wPartIDList == null) {
                wPartIDList = new ArrayList<>();
            }
            if (wStatusList == null) {
                wStatusList = new ArrayList<>();
            }

            boolean wIsHistory = wEndTime.compareTo(Calendar.getInstance()) <= 0;

            int wShiftID = MESServer.MES_QueryShiftID(wLoginUser.CompanyID, wEndTime, APSShiftPeriod.Day,
                    FMCShiftLevel.Day, 0);

            String wSQL = "";
            if (!wIsHistory) {
                wSQL = StringUtils.Format(
                        "SELECT t1.IsDispatched,t1.ID,t2.OrderNo,t5.Name as LineName,t6.CustomerName,t2.PartNo,"
                                + "t1.ReadyTime,t1.StartTime,t1.EndTime,t3.Name as PartName,t3.ID as PartID,t4.Name as "
                                + "StepName,t1.Status,t1.OperatorList FROM {0}.aps_taskstep t1,"
                                + "{0}.oms_order t2,{3}.fpc_part t3,{3}.fpc_partpoint t4,"
                                + "{3}.fmc_line t5,{3}.crm_customer t6 where t2.BureauSectionID=t6.ID "
                                + "and t1.LineID=t5.ID and t1.StepID=t4.ID and t1.PartID=t3.ID and t1.OrderID=t2.ID "
                                + "and ( :wPartID is null or :wPartID = '''' or t1.PartID in ({1})) "
                                + "and ( :wStatus is null or :wStatus = '''' or t1.Status in ({2})) "
                                + "and ( :wIsDispatched < 0 or :wIsDispatched = t1.IsDispatched ) "
                                + "and  ((t1.ShiftID<=:wShiftID  and t1.Status !=5) or "
                                + "(:StartTime<t1.EndTime and :EndTime>t1.StartTime and t1.Status=5) ) group by t1.ID;",
                        wInstance.Result, wPartIDList.size() > 0 ? StringUtils.Join(",", wPartIDList) : "0",
                        wStatusList.size() > 0 ? StringUtils.Join(",", wStatusList) : "0", wInstance1.Result);
            } else {
                wSQL = StringUtils.Format(
                        "SELECT t1.IsDispatched,t1.ID,t2.OrderNo,t5.Name as LineName,t6.CustomerName,t2.PartNo,t1" +
                                ".ReadyTime,t1.StartTime,"
                                + "t1.EndTime,t3.Name as PartName,t3.ID as PartID,t4.Name as StepName,t1.Status,t1" +
                                ".OperatorList "
                                + "FROM {0}.aps_taskstep t1,{0}.oms_order t2,{3}.fpc_part t3,"
                                + "{3}.fpc_partpoint t4,{3}.fmc_line t5,{3}.crm_customer t6 where "
                                + "t2.BureauSectionID=t6.ID and t1.LineID=t5.ID and t1.StepID=t4.ID and t1.PartID=t3" +
                                ".ID "
                                + "and ( :wPartID is null or :wPartID = '''' or t1.PartID in ({1})) "
                                + "and ( :wStatus is null or :wStatus = '''' or t1.Status in ({2})) "
                                + "and ( :wIsDispatched < 0 or :wIsDispatched = t1.IsDispatched ) "
                                + "and t1.OrderID=t2.ID and  ((t1.ShiftID<=:wShiftID  and t1.Status !=5) "
                                + "or (:StartTime<t1.EndTime and :EndTime>t1.StartTime and t1.Status=5) ) "
                                + "and t1.Status in(2,4,5) group by t1.ID;",
                        wInstance.Result, wPartIDList.size() > 0 ? StringUtils.Join(",", wPartIDList) : "0",
                        wStatusList.size() > 0 ? StringUtils.Join(",", wStatusList) : "0", wInstance1.Result);
            }

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("StartTime", wStartTime);
            wParamMap.put("EndTime", wEndTime);
            wParamMap.put("wShiftID", wShiftID);
            wParamMap.put("wPartID", StringUtils.Join(",", wPartIDList));
            wParamMap.put("wStatus", StringUtils.Join(",", wStatusList));
            wParamMap.put("wIsDispatched", wIsDispatched);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wMap : wQueryResult) {
                APSTaskStepInfo wItem = new APSTaskStepInfo();

                wItem.ID = StringUtils.parseInt(wMap.get("ID"));
                APSTaskStepInfo wInfo = this.QueryDispatchInfo(wLoginUser, wItem.ID, wErrorCode);
                wItem.ClassName = wInfo.ClassName;
                wItem.Dispather = wInfo.Dispather;
                wItem.CustomerName = StringUtils.parseString(wMap.get("CustomerName"));
                wItem.EndTime = StringUtils.parseCalendar(wMap.get("EndTime"));
                wItem.LineName = StringUtils.parseString(wMap.get("LineName"));
                wItem.OrderNo = StringUtils.parseString(wMap.get("OrderNo"));
                wItem.PartName = StringUtils.parseString(wMap.get("PartName"));
                wItem.PartID = StringUtils.parseInt(wMap.get("PartID"));
                wItem.PartNo = StringUtils.parseString(wMap.get("PartNo"));
                wItem.ReadyTime = StringUtils.parseCalendar(wMap.get("ReadyTime"));
                wItem.StartTime = StringUtils.parseCalendar(wMap.get("StartTime"));
                wItem.Status = StringUtils.parseInt(wMap.get("Status"));
                wItem.IsDispatched = StringUtils.parseInt(wMap.get("IsDispatched"));
                wItem.StepName = StringUtils.parseString(wMap.get("StepName"));
                wItem.Operators = this.GetOperators(StringUtils.parseString(wMap.get("OperatorList")));

                wResult.add(wItem);
            }

            if (wResult.size() > 0 && wClassIDList.size() > 0) {
                List<Integer> wNewClassList = wClassIDList;
                wResult = wResult.stream()
                        .filter(p -> wNewClassList.stream()
                                .anyMatch(q -> APSConstans.GetBMSDepartmentName(q).equals(p.ClassName)))
                        .collect(Collectors.toList());
            }
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 根据人员ID字符串获取人员列表
     */
    private String GetOperators(String wOperatorList) {
        String wResult = "";
        try {
            if (StringUtils.isEmpty(wOperatorList)) {
                return wResult;
            }

            String[] wStrs = wOperatorList.split("[,;]");
            List<String> wNames = new ArrayList<>();
            for (String wStr : wStrs) {
                String wName = APSConstans.GetBMSEmployeeName(Integer.parseInt(wStr));
                if (StringUtils.isNotEmpty(wName)) {
                    wNames.add(wName);
                }
            }
            wResult = StringUtils.Join(",", wNames);
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 获取工序任务详情(质量三检进度)
     */
    public List<APSTaskStepDetails> SelectAPSTaskStepDetails(BMSEmployee wLoginUser, int wAPSTaskPartID,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStepDetails> wResult = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance2 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.EXC,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance2.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "SELECT   (select count(*) as TotalSize from {2}.ipt_itemrecord where ItemType!=4 and vid in(  " +
                            "SELECT ModuleVersionID FROM {1}.sfc_taskipt where TaskStepID=t1.ID and TaskType=6)) as " +
                            "TSize,"
                            + "(select count(distinct(IPTItemID)) as FinishSize from {2}.ipt_value where TaskID in( " +
                            "SELECT ID FROM {1}.sfc_taskipt where TaskStepID=t1.ID and TaskType=6) and Status=2) as " +
                            "SelfFSize,"
                            + "(select count(distinct(IPTItemID)) as FinishSize from {2}.ipt_value where TaskID in( " +
                            "SELECT ID FROM {1}.sfc_taskipt where TaskStepID=t1.ID and TaskType=12) and Status=2) as " +
                            "MFSize,"
                            + "(select count(distinct(IPTItemID)) as FinishSize from {2}.ipt_value where TaskID in( " +
                            "SELECT ID FROM {1}.sfc_taskipt where TaskStepID=t1.ID and TaskType=13) and Status=2) as " +
                            "SFSize,"
                            + "(select count(*) as TotalSize from {2}.ipt_itemrecord where ItemType!=4 and vid in(  " +
                            "SELECT ModuleVersionID FROM {1}.sfc_taskipt where TaskStepID=t1.ID and TaskType=14)) as " +
                            "PTSize,"
                            + "(select count(distinct(IPTItemID)) as FinishSize from {2}.ipt_value where TaskID in( " +
                            "SELECT ID FROM {1}.sfc_taskipt where TaskStepID=t1.ID and TaskType=14) and Status=2) as " +
                            "PFSize,"
                            + "t1.OrderID,t1.ID, t2.PartType as Type,t2.Name as PartName,t2.ID as PartID,"
                            + "t3.Name as StepName,t4.Name as LineName,t1.PartNo,t1.Status,t5.ProductID,t1.StepID "
                            + "FROM {0}.aps_taskstep t1,{1}.fpc_part t2,"
                            + "{1}.fpc_partpoint t3,{1}.fmc_line t4,{1}.oms_order t5 where t1.PartID=t2.ID and t1" +
                            ".OrderID=t5.ID "
                            + "and t1.StepID=t3.ID and t1.LineID=t4.ID and TaskPartID=:TaskPartID and t1.Active=1;",
                    wInstance.Result, wInstance1.Result, wInstance2.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("TaskPartID", wAPSTaskPartID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wMap : wQueryResult) {
                APSTaskStepDetails wAPSTaskStepDetails = new APSTaskStepDetails();

                wAPSTaskStepDetails.ID = StringUtils.parseInt(wMap.get("ID"));
                wAPSTaskStepDetails.LineName = StringUtils.parseString(wMap.get("LineName"));
                wAPSTaskStepDetails.MFSize = StringUtils.parseInt(wMap.get("MFSize"));
                wAPSTaskStepDetails.PartID = StringUtils.parseInt(wMap.get("PartID"));
                wAPSTaskStepDetails.PartName = StringUtils.parseString(wMap.get("PartName"));
                wAPSTaskStepDetails.PFSize = StringUtils.parseInt(wMap.get("PFSize"));
                wAPSTaskStepDetails.PartNo = StringUtils.parseString(wMap.get("PartNo"));
                wAPSTaskStepDetails.PTSize = StringUtils.parseInt(wMap.get("PTSize"));
                wAPSTaskStepDetails.SelfFSize = StringUtils.parseInt(wMap.get("SelfFSize"));
                wAPSTaskStepDetails.SFSize = StringUtils.parseInt(wMap.get("SFSize"));
                wAPSTaskStepDetails.Status = StringUtils.parseInt(wMap.get("Status"));
                wAPSTaskStepDetails.StepName = StringUtils.parseString(wMap.get("StepName"));
                wAPSTaskStepDetails.TSize = StringUtils.parseInt(wMap.get("TSize"));
                wAPSTaskStepDetails.Type = StringUtils.parseInt(wMap.get("Type"));
                wAPSTaskStepDetails.OrderID = StringUtils.parseInt(wMap.get("OrderID"));

                wAPSTaskStepDetails.ProductID = StringUtils.parseInt(wMap.get("ProductID"));
                wAPSTaskStepDetails.PartPointID = StringUtils.parseInt(wMap.get("StepID"));

                wResult.add(wAPSTaskStepDetails);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 获取工序任务集合
     */
    public List<APSTaskStep> SelectAPSTaskStepList(BMSEmployee wLoginUser, Calendar wShiftEnd,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResult = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance2 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.EXC,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance2.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "select distinct(ID) TaskStepID from {0}.aps_taskstep where :EndTime>PlanStartTime and "
                            + "TaskPartID in(SELECT distinct(TaskPartID) FROM {0}.aps_taskstep "
                            + "where Status=1 and TaskPartID in(SELECT distinct(ID) as TaskPartID FROM "
                            + "{0}.aps_taskpart where Status in(2,3,4)  "
                            + "and ShiftPeriod=5 and Active=1 and PartID in (SELECT distinct(StationID) FROM "
                            + "{2}.lfs_workareastation where WorkAreaID in(SELECT ID FROM {1}.bms_department "
                            + "where ID in(SELECT DepartmentID FROM {1}.mbs_user where ID=:UserID) and Type=2 "
                            + "and 1 in(SELECT count(*) FROM {1}.bms_position where ID in(SELECT Position "
                            + "FROM {1}.mbs_user where ID=:UserID) and DutyID=2)) and Active=1) and Active=1))",
                    wInstance.Result, wInstance1.Result, wInstance2.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("EndTime", wShiftEnd);
            wParamMap.put("UserID", wLoginUser.ID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            List<Integer> wTaskStepIDList = new ArrayList<>();
            for (Map<String, Object> wMap : wQueryResult) {
                int wTaskStepID = StringUtils.parseInt(wMap.get("TaskStepID"));
                if (wTaskStepID > 0) {
                    wTaskStepIDList.add(wTaskStepID);
                }
            }
            if (wTaskStepIDList.size() > 0) {
                wResult = APSTaskStepDAO.getInstance().SelectListByIDList(wLoginUser, wTaskStepIDList, wErrorCode);
            }
        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    /**
     * 获取车号排序的日计划
     */
    public List<APSPartNoDetails> SelectAPSPartNoDetailsList(BMSEmployee wLoginUser, Calendar wStartTime,
            Calendar wEndTime, int wWorkAreaID,
            OutResult<Integer> wErrorCode) {
        List<APSPartNoDetails> wResult = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.EXC,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "select t1.* from  {0}.aps_taskstep t1, {0}.aps_taskpart t2," + "{1}.lfs_workareastation t3  "
                            + "where t1.Active=1 and t1.TaskPartID=t2.ID and t2.PartID=t3.StationID "
                            + "and ( :WorkAreaID < 0 or :WorkAreaID = t3.WorkAreaID ) " + "and t1.TaskPartID in  "
                            + "(SELECT distinct(TaskPartID) FROM  {0}.aps_taskstep t1, {0}.aps_taskpart t2 "
                            + "where t1.Active=1 and t1.TaskPartID=t2.ID and t2.Active=1  "
                            + "and (t1.Status != 5 or (t1.Status=5 and :StartTime < t1.EndTime "
                            + "and :EndTime)>t1.StartTime ) and t1.TaskPartID>0);",
                    wInstance.Result, wInstance1.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("StartTime", wStartTime);
            wParamMap.put("EndTime", wEndTime);
            wParamMap.put("WorkAreaID", wWorkAreaID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            List<APSTaskStep> wList = new ArrayList<>();
            for (Map<String, Object> wMap : wQueryResult) {
                APSTaskStep wAPSTaskStep = new APSTaskStep();
                wAPSTaskStep.PartNo = StringUtils.parseString(wMap.get("PartNo"));
                wAPSTaskStep.OrderID = StringUtils.parseInt(wMap.get("OrderID"));
                wAPSTaskStep.Status = StringUtils.parseInt(wMap.get("Status"));
                wList.add(wAPSTaskStep);
            }

            List<Integer> wOrderIDList = wList.stream().map(p -> p.OrderID).distinct().collect(Collectors.toList());

            List<OMSOrder> wOrderList = OMSOrderDAO.getInstance().SelectListByIDList(wLoginUser, wOrderIDList,
                    wErrorCode);
            // 订单排序
            wOrderList.sort(Comparator.comparing(OMSOrder::getERPID).thenComparing(OMSOrder::getRealReceiveDate));

            for (OMSOrder wOMSOrder : wOrderList) {
                APSPartNoDetails wAPSPartNoDetails = new APSPartNoDetails();
                wAPSPartNoDetails.OrderID = wOMSOrder.ID;
                wAPSPartNoDetails.PartNo = wList.stream().filter(p -> p.OrderID == wOMSOrder.ID).findFirst()
                        .get().PartNo;
                wAPSPartNoDetails.StepSize = (int) wList.stream().filter(p -> p.OrderID == wOMSOrder.ID).count();
                wAPSPartNoDetails.StepFinish = (int) wList.stream()
                        .filter(p -> p.OrderID == wOMSOrder.ID && p.Status == 5).count();
                wAPSPartNoDetails.StepSchedule = (int) wList.stream()
                        .filter(p -> p.OrderID == wOMSOrder.ID && (p.Status == 2 || p.Status == 4 || p.Status == 5))
                        .count();
                wAPSPartNoDetails.StepMaking = (int) wList.stream()
                        .filter(p -> p.OrderID == wOMSOrder.ID && (p.Status == 8 || p.Status == 9 || p.Status == 10))
                        .count();
                wResult.add(wAPSPartNoDetails);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 获取工区分类的日计划
     */

    public List<APSWorkAreaDetails> SelectAPSWorkAreaDetailsList(BMSEmployee wLoginUser, Calendar wStartTime,
            Calendar wEndTime, int wOrderID,
            OutResult<Integer> wErrorCode) {
        List<APSWorkAreaDetails> wResult = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance2 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.EXC,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance2.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format("select t2.WorkAreaID,t3.Name as WorkArea,t1.* from {0}.aps_taskstep t1,"
                    + "{2}.lfs_workareastation t2,{1}.bms_department t3 "
                    + "where t1.Active=1 and t2.WorkAreaID=t3.ID and t1.PartID =t2.StationID and " +
                    "OrderID=:OrderID "
                    + "and TaskPartID in (SELECT distinct(TaskPartID) FROM {0}.aps_taskstep t1,"
                    + "{0}.aps_taskpart t2 where  t1.TaskPartID=t2.ID and t2.Active=1 "
                    + "and (t1.Status != 5 or (t1.Status=5 and :StartTime < t1.EndTime "
                    + "and :EndTime)>t1.StartTime ) and t1.TaskPartID>0);", wInstance.Result, wInstance1.Result,
                    wInstance2.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("StartTime", wStartTime);
            wParamMap.put("EndTime", wEndTime);
            wParamMap.put("OrderID", wOrderID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            List<APSTaskStep> wList = new ArrayList<>();
            for (Map<String, Object> wMap : wQueryResult) {
                APSTaskStep wAPSTaskStep = new APSTaskStep();
                wAPSTaskStep.PartNo = StringUtils.parseString(wMap.get("PartNo"));
                wAPSTaskStep.OrderID = StringUtils.parseInt(wMap.get("OrderID"));
                wAPSTaskStep.Status = StringUtils.parseInt(wMap.get("Status"));
                wAPSTaskStep.AreaID = StringUtils.parseInt(wMap.get("WorkAreaID"));
                wAPSTaskStep.AreaName = StringUtils.parseString(wMap.get("WorkArea"));
                wList.add(wAPSTaskStep);
            }

            List<Integer> wAreaIDList = wList.stream().map(p -> p.AreaID).distinct().collect(Collectors.toList());
            for (Integer wAraID : wAreaIDList) {
                APSWorkAreaDetails wAPSWorkAreaDetails = new APSWorkAreaDetails();
                wAPSWorkAreaDetails.AreaID = wAraID;
                wAPSWorkAreaDetails.AreaName = wList.stream().filter(p -> p.AreaID == wAraID).findFirst()
                        .get().AreaName;
                wAPSWorkAreaDetails.PartNo = wList.stream().filter(p -> p.AreaID == wAraID).findFirst().get().PartNo;
                wAPSWorkAreaDetails.OrderID = wOrderID;
                wAPSWorkAreaDetails.StepSize = (int) wList.stream().filter(p -> p.AreaID == wAraID).count();
                wAPSWorkAreaDetails.StepFinish = (int) wList.stream().filter(p -> p.AreaID == wAraID && p.Status == 5)
                        .count();
                wAPSWorkAreaDetails.StepSchedule = (int) wList.stream()
                        .filter(p -> p.AreaID == wAraID && (p.Status == 2 || p.Status == 4 || p.Status == 5)).count();
                wAPSWorkAreaDetails.StepMaking = (int) wList.stream()
                        .filter(p -> p.AreaID == wAraID && (p.Status == 8 || p.Status == 9 || p.Status == 10)).count();
                wResult.add(wAPSWorkAreaDetails);
            }

            // 排序
            if (wResult.size() > 0) {
                wResult.sort(Comparator.comparing(APSWorkAreaDetails::getAreaID));
            }

        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 获取工序列表
     */
    public List<APSTaskStep> SelectQueryTaskStep(BMSEmployee wLoginUser, Calendar wStartTime, Calendar wEndTime,
            int wAreaID, int wOrderID, OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResult = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance2 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.EXC,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance2.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "select t2.WorkAreaID,t2.OrderNum,t3.Name as WorkArea,t1.* from {0}.aps_taskstep t1,"
                            + "{2}.lfs_workareastation t2,{1}.bms_department t3 "
                            + "where t1.Active=1 and t2.WorkAreaID=t3.ID and t1.PartID =t2.StationID  "
                            + "and ( :wAreaID <= 0 or :wAreaID = t2.WorkAreaID ) "
                            + "and ( :wOrderID <= 0 or :wOrderID = t1.OrderID ) " + "and TaskPartID "
                            + "in (SELECT distinct(TaskPartID) FROM {0}.aps_taskstep t1,"
                            + "{0}.aps_taskpart t2 where  t1.TaskPartID=t2.ID and t2.Active=1 "
                            + "and (t1.Status != 5 or (t1.Status=5 and :StartTime < t1.EndTime "
                            + "and :EndTime>t1.StartTime )) and t1.TaskPartID>0);",
                    wInstance.Result, wInstance1.Result, wInstance2.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("StartTime", wEndTime);
            wParamMap.put("EndTime", wEndTime);
            wParamMap.put("wAreaID", wAreaID);
            wParamMap.put("wOrderID", wOrderID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                APSTaskStep wItem = new APSTaskStep();

                wItem.ID = StringUtils.parseInt(wReader.get("ID"));
                wItem.OrderNum = StringUtils.parseInt(wReader.get("OrderNum"));
                wItem.AreaID = StringUtils.parseInt(wReader.get("WorkAreaID"));
                wItem.AreaName = StringUtils.parseString(wReader.get("WorkArea"));
                wItem.OrderID = StringUtils.parseInt(wReader.get("OrderID"));
                wItem.PartNo = StringUtils.parseString(wReader.get("PartNo"));
                wItem.TaskLineID = StringUtils.parseInt(wReader.get("TaskLineID"));
                wItem.TaskPartID = StringUtils.parseInt(wReader.get("TaskPartID"));
                wItem.WorkShopID = StringUtils.parseInt(wReader.get("WorkShopID"));
                wItem.LineID = StringUtils.parseInt(wReader.get("LineID"));
                wItem.PartID = StringUtils.parseInt(wReader.get("PartID"));
                wItem.StepID = StringUtils.parseInt(wReader.get("StepID"));
                wItem.ShiftID = StringUtils.parseInt(wReader.get("ShiftID"));
                wItem.StartTime = StringUtils.parseCalendar(wReader.get("StartTime"));
                wItem.CreateTime = StringUtils.parseCalendar(wReader.get("CreateTime"));
                wItem.EndTime = StringUtils.parseCalendar(wReader.get("EndTime"));
                wItem.ReadyTime = StringUtils.parseCalendar(wReader.get("ReadyTime"));
                wItem.PlanStartTime = StringUtils.parseCalendar(wReader.get("PlanStartTime"));
                wItem.Status = StringUtils.parseInt(wReader.get("Status"));
                wItem.Active = StringUtils.parseInt(wReader.get("Active"));
                wItem.ProductNo = StringUtils.parseString(wReader.get("ProductNo"));
                wItem.MaterialNo = StringUtils.parseString(wReader.get("MaterialNo"));
                wItem.PlanerID = StringUtils.parseInt(wReader.get("PlannerID"));
                wItem.TaskText = StringUtils.parseString(wReader.get("TaskText"));
                wItem.WorkHour = StringUtils.parseDouble(wReader.get("WorkHour"));
                wItem.RealHour = StringUtils.parseDouble(wReader.get("RealHour"));
                wItem.OperatorList = StringUtils
                        .parseIntList(StringUtils.parseString(wReader.get("OperatorList")).split("[,;]"));
                wItem.IsDispatched = StringUtils.parseInt(wReader.get("IsDispatched")) == 1;
                wItem.RemarkList = APSTaskRemark.StringToList(StringUtils.parseString(wReader.get("RemarkList")));
                wItem.Remark = new APSTaskRemark(StringUtils.parseString(wReader.get("Remark")));

                wItem.LineName = APSConstans.GetFMCLineName(wItem.LineID);
                wItem.PartName = APSConstans.GetFPCPartName(wItem.PartID);
                wItem.StepName = APSConstans.GetFPCPartPointName(wItem.StepID);

                wItem.OrderNo = StringUtils.parseString(wReader.get("OrderNo"));

                wResult.add(wItem);
            }
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 自动完成工序任务
     */
    public void AutoFinishTask(BMSEmployee wLoginUser, OutResult<Integer> wErrorCode) {
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return;
            }

            String wSQL = StringUtils.Format("SELECT t1.* FROM {0}.aps_taskstep t1,{1}.sfc_taskipt t2,"
                    + "{1}.sfc_taskipt t3 where t1.ID=t2.TaskStepID and t2.Status=2 "
                    + "and t2.TaskType=6 and t3.TaskStepID=t1.ID and t3.Status=2 "
                    + "and t3.TaskType=12 and t1.Status=4;", wInstance.Result, wInstance1.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            List<APSTaskStep> wList = new ArrayList<>();
            for (Map<String, Object> wReader : wQueryResult) {
                APSTaskStep wItem = new APSTaskStep();

                wItem.ID = StringUtils.parseInt(wReader.get("ID"));
                wItem.OrderID = StringUtils.parseInt(wReader.get("OrderID"));
                wItem.PartNo = StringUtils.parseString(wReader.get("PartNo"));
                wItem.TaskLineID = StringUtils.parseInt(wReader.get("TaskLineID"));
                wItem.TaskPartID = StringUtils.parseInt(wReader.get("TaskPartID"));
                wItem.WorkShopID = StringUtils.parseInt(wReader.get("WorkShopID"));
                wItem.LineID = StringUtils.parseInt(wReader.get("LineID"));
                wItem.PartID = StringUtils.parseInt(wReader.get("PartID"));
                wItem.StepID = StringUtils.parseInt(wReader.get("StepID"));
                wItem.ShiftID = StringUtils.parseInt(wReader.get("ShiftID"));
                wItem.StartTime = StringUtils.parseCalendar(wReader.get("StartTime"));
                wItem.CreateTime = StringUtils.parseCalendar(wReader.get("CreateTime"));
                wItem.EndTime = StringUtils.parseCalendar(wReader.get("EndTime"));
                wItem.ReadyTime = StringUtils.parseCalendar(wReader.get("ReadyTime"));
                wItem.PlanStartTime = StringUtils.parseCalendar(wReader.get("PlanStartTime"));
                wItem.Status = StringUtils.parseInt(wReader.get("Status"));
                wItem.Active = StringUtils.parseInt(wReader.get("Active"));
                wItem.ProductNo = StringUtils.parseString(wReader.get("ProductNo"));
                wItem.MaterialNo = StringUtils.parseString(wReader.get("MaterialNo"));
                wItem.PlanerID = StringUtils.parseInt(wReader.get("PlannerID"));
                wItem.TaskText = StringUtils.parseString(wReader.get("TaskText"));
                wItem.WorkHour = StringUtils.parseDouble(wReader.get("WorkHour"));
                wItem.RealHour = StringUtils.parseDouble(wReader.get("RealHour"));
                wItem.OperatorList = StringUtils
                        .parseIntList(StringUtils.parseString(wReader.get("OperatorList")).split("[,;]"));
                wItem.IsDispatched = StringUtils.parseInt(wReader.get("IsDispatched")) == 1;
                wItem.RemarkList = APSTaskRemark.StringToList(StringUtils.parseString(wReader.get("RemarkList")));
                wItem.Remark = new APSTaskRemark(StringUtils.parseString(wReader.get("Remark")));
                wItem.OrderNo = StringUtils.parseString(wReader.get("OrderNo"));

                wList.add(wItem);
            }

            if (wList.size() > 0) {
                for (APSTaskStep wAPSTaskStep : wList) {
                    wAPSTaskStep.Status = 5;
                    wAPSTaskStep.EndTime = Calendar.getInstance();
                    APSTaskStepDAO.getInstance().Update(wLoginUser, wAPSTaskStep, wErrorCode);
                }
            }
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
    }

    /**
     * 根据订单和工位获取工序任务集合
     */
    public List<APSTaskStep> APS_QueryOrderTimeInfoList(BMSEmployee wLoginUser, int wOrderID, String wStationName,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResult = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            ServiceResult<String> wInstance1 = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance1.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format("SELECT ID FROM {0}.aps_taskstep where "
                    + "TaskPartID in (SELECT t1.ID FROM {0}.aps_taskpart t1,{1}.fpc_part t2 "
                    + "where t1.PartID=t2.ID and t1.OrderID=:OrderID and t2.Name=:StationName and t1" +
                    ".ShiftPeriod=5 and t1.Active=1);",
                    wInstance.Result, wInstance1.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("OrderID", wOrderID);
            wParamMap.put("StationName", wStationName);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            List<Integer> wTaskStepIDList = new ArrayList<>();
            for (Map<String, Object> wMap : wQueryResult) {
                int wTaskStepID = StringUtils.parseInt(wMap.get("ID"));
                if (wTaskStepID > 0) {
                    wTaskStepIDList.add(wTaskStepID);
                }
            }
            if (wTaskStepIDList.size() > 0) {
                wResult = APSTaskStepDAO.getInstance().SelectListByIDList(wLoginUser, wTaskStepIDList, wErrorCode);
            }
        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    /**
     * 查询shiftID小于指定ShiftID的日计划(状态为下达)
     */
    public List<APSTaskStep> SelectListByShiftID(BMSEmployee wAdminUser, int wShiftID, OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResult = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wAdminUser.getCompanyID(), MESDBSource.APS,
                    wAdminUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "SELECT * FROM {0}.aps_taskstep " + "where Status=2 and ShiftID < :ShiftID;", wInstance.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("ShiftID", wShiftID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            SetValue(wResult, wQueryResult);
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 获取标准工时
     */
    public double GetActualPeriod(BMSEmployee wLoginUser, int routeID, int partID, int stepID,
            OutResult<Integer> wErrorCode) {
        double wResult = 0;
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "SELECT ActualPeriod FROM {0}.fpc_routepartpoint "
                            + "where RouteID=:RouteID and PartID=:PartID and PartPointID=:PartPointID;",
                    wInstance.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("RouteID", routeID);
            wParamMap.put("PartID", partID);
            wParamMap.put("PartPointID", stepID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                wResult = StringUtils.parseDouble(wReader.get("ActualPeriod"));
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 通过订单ID集合和工位ID集合获取数据集合
     */
    public List<APSTaskStep> SelectList(BMSEmployee wLoginUser, String wOrderIDs, String wPartIDs,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResultList = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            String wSQL = StringUtils.Format(
                    "SELECT t1.*,t2.OrderNo " + "FROM {0}.aps_taskstep t1,{0}.oms_order t2  WHERE t1.OrderID=t2.ID "
                            + "and ( t1.OrderID in ({1}) ) " + "and ( t1.PartID in ({2}) ) and t1.Active=1 ;",
                    wInstance.Result, wOrderIDs, wPartIDs);

            Map<String, Object> wParamMap = new HashMap<>();

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            SetValue(wResultList, wQueryResult);
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResultList;
    }

    public List<Integer> SelectNotRealFinishedTaskStepIDList(BMSEmployee wLoginUser, OutResult<Integer> wErrorCode) {
        List<Integer> wResult = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "select t1.TaskStepID from {0}.sfc_taskipt t1,{0}.aps_taskstep t2 where "
                            + "t1.TaskType=13 and t1.status = 1 "
                            + "and t1.TaskStepID=t2.ID and t2.Status=5 and t1.SubmitTime>''2021-9-1 00:00:00'';",
                    wInstance.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                int wTaskStepID = StringUtils.parseInt(wReader.get("TaskStepID"));
                wResult.add(wTaskStepID);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    public APSTaskStepDetails GetTaskStatus(BMSEmployee wLoginUser, int wTaskStepID, OutResult<Integer> wErrorCode) {
        APSTaskStepDetails wResult = new APSTaskStepDetails();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format("SELECT TaskType,Status FROM {0}.sfc_taskipt WHERE " +
                    "taskstepid=:wTaskStepID;",
                    wInstance.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("wTaskStepID", wTaskStepID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                int wTaskType = StringUtils.parseInt(wReader.get("TaskType"));
                int wStatus = StringUtils.parseInt(wReader.get("Status"));
                if (wTaskType == 6) {
                    wResult.STaskStatus = wStatus;
                } else if (wTaskType == 12) {
                    wResult.MTaskStatus = wStatus;
                } else if (wTaskType == 13) {
                    wResult.SpTaskStatus = wStatus;
                }
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 删除对应的检验任务
     */
    public void DisableRelaTaskIPT(BMSEmployee wLoginUser, int wTaskStepID, OutResult<Integer> wErrorCode) {
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return;
            }

            String wSQL = StringUtils.Format("delete from {0}.sfc_taskipt WHERE taskstepid=:taskstepid AND " +
                    "ID>0;",
                    wInstance.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("taskstepid", wTaskStepID);

            wSQL = this.DMLChange(wSQL);

            shrisJdbcTemplate.update(wSQL, wParamMap);
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
    }

    public void StartSFCTaskStep(BMSEmployee wLoginUser, int wTaskStepID, OutResult<Integer> wErrorCode) {
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return;
            }

            String wSQL = StringUtils.Format("UPDATE {0}.sfc_taskstep SET IsStartWork=0 WHERE TaskStepID=:TaskStepID " +
                    "AND ID>0;",
                    wInstance.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("TaskStepID", wTaskStepID);

            wSQL = this.DMLChange(wSQL);

            shrisJdbcTemplate.update(wSQL, wParamMap);
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
    }

    public void StartSFCTaskStepMessage(BMSEmployee wLoginUser, int wSFCTaskStepID, OutResult<Integer> wErrorCode) {
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return;
            }

            // 近一年的时间
            Calendar wStartTime = Calendar.getInstance();
            wStartTime.add(Calendar.YEAR, -1);
            Calendar wEndTime = Calendar.getInstance();
            wEndTime.add(Calendar.DATE, 1);

            // 查询派工消息，重新生成
            List<BFCMessage> wList = CoreServiceImpl.getInstance().BFC_GetMessageListByCondition(wLoginUser, -1, -1,
                    BFCMessageType.Task.getValue(),
                    StringUtils.parseListArgs(BPMEventModule.SCDispatching.getValue()), wSFCTaskStepID, -1,
                    StringUtils.parseListArgs(3, 4), -1, -1, wStartTime, wEndTime).List(BFCMessage.class);
            if (wList == null || wList.size() <= 0) {
                return;
            }

            for (BFCMessage bfcMessage : wList) {
                bfcMessage.ID = 0;
                bfcMessage.Active = 0;
            }
            CoreServiceImpl.getInstance().BFC_UpdateMessageList(wLoginUser, wList);
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
    }

    /**
     * 获取关联检验任务字典
     */
    public Map<Integer, Integer> SelectTaskIPTIDListByTaskStepID(BMSEmployee wLoginUser, int wTaskStepID,
            OutResult<Integer> wErrorCode) {
        Map<Integer, Integer> wResult = new HashMap<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format("SELECT ID,TaskType FROM {0}.sfc_taskipt WHERE TaskStepID=:TaskStepID " +
                    "AND ACTIVE=1;",
                    wInstance.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("TaskStepID", wTaskStepID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                int wID = StringUtils.parseInt(wReader.get("ID"));
                int wTaskType = StringUtils.parseInt(wReader.get("TaskType"));
                wResult.put(wID, wTaskType);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    public void DisableTaskStepList(BMSEmployee wLoginUser, OutResult<Integer> wErrorCode) {
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return;
            }

            String wSQL = StringUtils.Format("UPDATE {0}.aps_taskstep t1 INNER JOIN {0}.aps_taskpart t2 " +
                    "ON t1.taskpartid=t2.id AND t2.active=2 AND t1.active=1 AND t1.status IN (1,2,4) SET t1" +
                    ".active=2 WHERE t1.ID>0;",
                    wInstance.Result);

            Map<String, Object> wParamMap = new HashMap<>();

            wSQL = this.DMLChange(wSQL);

            shrisJdbcTemplate.update(wSQL, wParamMap);
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
    }

    /**
     * 禁用检验任务
     */
    public void DisableTaskIPTList(BMSEmployee wLoginUser, List<Integer> wTaskStepIDList,
            OutResult<Integer> wErrorCode) {
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return;
            }

            if (wTaskStepIDList == null || wTaskStepIDList.size() <= 0) {
                return;
            }

            String wSQL = StringUtils.Format("UPDATE {0}.sfc_taskipt SET ACTIVE=2 WHERE TaskStepID IN ({1}) AND ID>0;",
                    wInstance.Result, StringUtils.Join(",", wTaskStepIDList));

            Map<String, Object> wParamMap = new HashMap<>();

            wSQL = this.DMLChange(wSQL);

            shrisJdbcTemplate.update(wSQL, wParamMap);
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
    }

    /**
     * 查询日计划主页面数据
     */
    public List<APSTaskStep> APS_QueryDayPlanMainList(BMSEmployee wLoginUser, Calendar wStartTime, Calendar wEndTime,
            int wProductID, int wLineID, int wCustomerID, int wOrderID,
            int wAreaID, int wPartID, int wStatus,
            OutResult<Integer> wErrorCode) {
        List<APSTaskStep> wResultList = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.APS,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResultList;
            }

            Calendar wBaseTime = Calendar.getInstance();
            wBaseTime.set(2000, 0, 1);
            if (wStartTime == null) {
                wStartTime = wBaseTime;
            }
            if (wEndTime == null) {
                wEndTime = wBaseTime;
            }

            String wStatusStr = "";
            if (wStatus == 1) {
                wStatusStr = "1";
            } else {
                wStatusStr = "2,3,4,5";
            }

            String wSQL = StringUtils.Format("SELECT t1.*,t2.OrderNo,t3.MaterialName,t4.WorkAreaID," +
                    "t5.Name WorkAreaName,t6.ID ProductID,t6.ProductNo,t7.ID CustomerID,t7.CustomerName," +
                    "t8.Name LineName,t9.Name PartName,t10.Name StepName FROM {0}.aps_taskstep t1" +
                    " left join {0}.oms_order t2 on t1.OrderID=t2.ID " +
                    " left join {0}.mss_material t3 on t1.MaterialNoNew=t3.MaterialNo "
                    + " left join {0}.lfs_workareastation t4 on t1.PartID=t4.StationID "
                    + " left join {0}.bms_department t5 on t4.WorkAreaID=t5.ID "
                    + " left join {0}.fpc_product t6 on t2.ProductID=t6.ID "
                    + " left join {0}.crm_customer t7 on t2.BureauSectionID=t7.ID "
                    + " left join {0}.fmc_line t8 on t1.LineID=t8.ID "
                    + " left join {0}.fpc_part t9 on t1.PartID=t9.ID "
                    + " left join {0}.fpc_partpoint t10 on t1.StepID=t10.ID "
                    + "WHERE 1=1 "
                    + "and ( :wProductID <= 0 or :wProductID = t2.ProductID ) "
                    + "and ( :wLineID <= 0 or :wLineID = t1.LineID ) "
                    + "and ( :wCustomerID <= 0 or :wCustomerID = t2.BureauSectionID ) "
                    + "and ( :wOrderID <= 0 or :wOrderID = t1.OrderID ) "
                    + "and ( :wAreaID <= 0 or :wAreaID = t4.WorkAreaID ) "
                    + "and ( :wPartID <= 0 or :wPartID = t1.PartID ) "
                    + "and ( t1.Active=1 ) "
                    + "and ( :wStartTime <= str_to_date(''2010-01-01'', ''%Y-%m-%d'') or :wStartTime <= t1" +
                    ".CreateTime) "
                    + "and ( :wEndTime <= str_to_date(''2010-01-01'', ''%Y-%m-%d'') or :wEndTime >= t1" +
                    ".CreateTime) "
                    + "and ( t1.Status in ({1}));", wInstance.Result, wStatusStr);

            Map<String, Object> wParamMap = new HashMap<>();

            wParamMap.put("wStartTime", wStartTime);
            wParamMap.put("wEndTime", wEndTime);
            wParamMap.put("wProductID", wProductID);
            wParamMap.put("wLineID", wLineID);
            wParamMap.put("wCustomerID", wCustomerID);
            wParamMap.put("wOrderID", wOrderID);
            wParamMap.put("wAreaID", wAreaID);
            wParamMap.put("wPartID", wPartID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                APSTaskStep wItem = new APSTaskStep();

                wItem.ID = StringUtils.parseInt(wReader.get("ID"));
                wItem.OrderID = StringUtils.parseInt(wReader.get("OrderID"));
                wItem.PartNo = StringUtils.parseString(wReader.get("PartNo"));
                wItem.TaskLineID = StringUtils.parseInt(wReader.get("TaskLineID"));
                wItem.TaskPartID = StringUtils.parseInt(wReader.get("TaskPartID"));
                wItem.WorkShopID = StringUtils.parseInt(wReader.get("WorkShopID"));
                wItem.LineID = StringUtils.parseInt(wReader.get("LineID"));
                wItem.LineName = StringUtils.parseString(wReader.get("LineName"));
                wItem.ProductID = StringUtils.parseInt(wReader.get("ProductID"));
                wItem.ProductNo = StringUtils.parseString(wReader.get("ProductNo"));
                wItem.CustomerID = StringUtils.parseInt(wReader.get("CustomerID"));
                wItem.CustomerName = StringUtils.parseString(wReader.get("CustomerName"));
                wItem.PartID = StringUtils.parseInt(wReader.get("PartID"));
                wItem.PartName = StringUtils.parseString(wReader.get("PartName"));
                wItem.StepID = StringUtils.parseInt(wReader.get("StepID"));
                wItem.StepName = StringUtils.parseString(wReader.get("StepName"));
                wItem.ShiftID = StringUtils.parseInt(wReader.get("ShiftID"));
                wItem.StartTime = StringUtils.parseCalendar(wReader.get("StartTime"));
                wItem.CreateTime = StringUtils.parseCalendar(wReader.get("CreateTime"));
                wItem.EndTime = StringUtils.parseCalendar(wReader.get("EndTime"));
                wItem.ReadyTime = StringUtils.parseCalendar(wReader.get("ReadyTime"));
                wItem.PlanStartTime = StringUtils.parseCalendar(wReader.get("PlanStartTime"));
                wItem.PlanEndTime = StringUtils.parseCalendar(wReader.get("PlanEndTime"));
                wItem.Status = StringUtils.parseInt(wReader.get("Status"));
                wItem.Active = StringUtils.parseInt(wReader.get("Active"));
                wItem.ProductNo = StringUtils.parseString(wReader.get("ProductNo"));
                wItem.MaterialNo = StringUtils.parseString(wReader.get("MaterialNo"));
                wItem.MaterialName = StringUtils.parseString(wReader.get("MaterialName"));
                wItem.PlanerID = StringUtils.parseInt(wReader.get("PlannerID"));
                wItem.TaskText = StringUtils.parseString(wReader.get("TaskText"));
                wItem.WorkHour = StringUtils.parseDouble(wReader.get("WorkHour"));
                wItem.RealHour = StringUtils.parseDouble(wReader.get("RealHour"));
                wItem.AreaID = StringUtils.parseInt(wReader.get("WorkAreaID"));
                wItem.AreaName = StringUtils.parseString(wReader.get("WorkAreaName"));
                wItem.OperatorList = StringUtils
                        .parseIntList(StringUtils.parseString(wReader.get("OperatorList")).split("[,;]"));
                wItem.IsDispatched = StringUtils.parseInt(wReader.get("IsDispatched")) == 1;
                wItem.RemarkList = APSTaskRemark.StringToList(StringUtils.parseString(wReader.get("RemarkList")));
                wItem.Remark = new APSTaskRemark(StringUtils.parseString(wReader.get("Remark")));
                wItem.OrderNo = StringUtils.parseString(wReader.get("OrderNo"));
                wItem.PartPointType = StringUtils.parseInt(wReader.get("PartPointType"));
                wItem.PartPointTypeText = FPCPartPointType.getEnumType(wItem.PartPointType).getLable();
                wItem.FQTY = StringUtils.parseDouble(wReader.get("FQTY"));
                wItem.MaterialNoNew = StringUtils.parseString(wReader.get("MaterialNoNew"));
                wItem.Operators = APSConstans.GetBMSEmployeeName(wItem.OperatorList);

                wResultList.add(wItem);
            }
        } catch (Exception ex) {
            wErrorCode.set(MESException.DBSQL.getValue());
            logger.error(ex.toString());
        }
        return wResultList;
    }

    /**
     * 根据订单、工位判断是否有不合格评审单
     */
    public boolean JudgeIsHasNCR(BMSEmployee wLoginUser, int wOrderID, int wPartID, OutResult<Integer> wErrorCode) {
        boolean wResult = false;
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return false;
            }

            String wSQL = StringUtils.Format("SELECT COUNT(*) FQTY FROM {0}.`ncr_task` WHERE OrderID=:OrderID AND " +
                    "StationID=:StationID;",
                    wInstance.Result);

            Map<String, Object> wParamMap = new HashMap<String, Object>();

            wParamMap.put("OrderID", wOrderID);
            wParamMap.put("StationID", wPartID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                int wFQTY = StringUtils.parseInt(wReader.get("FQTY"));
                if (wFQTY > 0) {
                    wResult = true;
                }
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 根据订单、工位判断是否有不合格评审单
     */
    public Map<Integer, Boolean> JudgeIsHasNCR(BMSEmployee wLoginUser, int wOrderID, List<Integer> wPartIDList,
            OutResult<Integer> wErrorCode) {
        Map<Integer, Boolean> wResult = new HashMap<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            if (wPartIDList == null || wPartIDList.size() <= 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format("SELECT distinct StationID FQTY FROM {0}.`ncr_task` WHERE " +
                    "OrderID=:OrderID AND " +
                    "StationID in ({1});",
                    wInstance.Result, StringUtils.Join(",", wPartIDList));

            Map<String, Object> wParamMap = new HashMap<String, Object>();

            wParamMap.put("OrderID", wOrderID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                int wStationID = StringUtils.parseInt(wReader.get("StationID"));
                wResult.put(wStationID, true);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 查询物料领用单数据
     */
    public Map<Integer, Integer> WMS_QueryPickDemandMap(BMSEmployee wLoginUser, int wOrderID, int wPartID,
            List<Integer> wStepIDList, OutResult<Integer> wErrorCode) {
        Map<Integer, Integer> wResult = new HashMap<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            if (wStepIDList == null || wStepIDList.size() <= 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "SELECT DISTINCT PartPointID FROM {0}.`wms_pickdemanditem` t LEFT JOIN {0}.`wms_pickdemand` t1 " +
                            "ON t.DemandID=t1.ID WHERE t1.OrderID=:OrderID AND t.PartID=:PartID AND t.PartPointID IN " +
                            "({1});",
                    wInstance.Result, StringUtils.Join(",", wStepIDList));

            Map<String, Object> wParamMap = new HashMap<String, Object>();

            wParamMap.put("OrderID", wOrderID);
            wParamMap.put("PartID", wPartID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                int wPartPointID = StringUtils.parseInt(wReader.get("PartPointID"));
                wResult.put(wPartPointID, 1);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 查询物料领用单数据
     */
    public Map<Integer, Integer> WMS_QueryPickDemandMap(BMSEmployee wLoginUser, int wOrderID, List<Integer> wPartIDList,
            List<Integer> wStepIDList, OutResult<Integer> wErrorCode) {
        Map<Integer, Integer> wResult = new HashMap<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            if (wStepIDList == null || wStepIDList.size() <= 0) {
                return wResult;
            }

            if (wPartIDList == null || wPartIDList.size() <= 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "SELECT DISTINCT PartPointID FROM {0}.`wms_pickdemanditem` t LEFT JOIN {0}.`wms_pickdemand` t1 " +
                            "ON t.DemandID=t1.ID WHERE t1.OrderID=:OrderID AND t.PartID in ({2}) AND t.PartPointID IN" +
                            " " +
                            "({1});",
                    wInstance.Result, StringUtils.Join(",", wStepIDList), StringUtils.Join(",", wPartIDList));

            Map<String, Object> wParamMap = new HashMap<String, Object>();

            wParamMap.put("OrderID", wOrderID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                int wPartPointID = StringUtils.parseInt(wReader.get("PartPointID"));
                wResult.put(wPartPointID, 1);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 查询偶换件评审单数据
     */
    public Map<Integer, Integer> WMS_QueryBOMTaskMap(BMSEmployee wLoginUser, int wOrderID, int wPartID,
            List<Integer> wStepIDList, OutResult<Integer> wErrorCode) {
        Map<Integer, Integer> wResult = new HashMap<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            if (wStepIDList == null || wStepIDList.size() <= 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "SELECT DISTINCT PartPointID FROM {0}.`sfc_bomtask` WHERE OrderID=:OrderID AND PartID=:PartID AND" +
                            " PartPointID IN ({1});",
                    wInstance.Result, StringUtils.Join(",", wStepIDList));

            Map<String, Object> wParamMap = new HashMap<String, Object>();

            wParamMap.put("OrderID", wOrderID);
            wParamMap.put("PartID", wPartID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                int wPartPointID = StringUtils.parseInt(wReader.get("PartPointID"));
                wResult.put(wPartPointID, 1);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 查询偶换件评审单数据
     */
    public Map<Integer, Integer> WMS_QueryBOMTaskMap(BMSEmployee wLoginUser, int wOrderID, List<Integer> wPartIDList,
            List<Integer> wStepIDList, OutResult<Integer> wErrorCode) {
        Map<Integer, Integer> wResult = new HashMap<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(wLoginUser.getCompanyID(), MESDBSource.Basic,
                    wLoginUser.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            if (wStepIDList == null || wStepIDList.size() <= 0) {
                return wResult;
            }

            if (wPartIDList == null || wPartIDList.size() <= 0) {
                return wResult;
            }

            String wSQL = StringUtils.Format(
                    "SELECT DISTINCT PartPointID FROM {0}.`sfc_bomtask` WHERE OrderID=:OrderID AND PartID in ({2}) " +
                            "AND" +
                            " PartPointID IN ({1});",
                    wInstance.Result, StringUtils.Join(",", wStepIDList), StringUtils.Join(",", wPartIDList));

            Map<String, Object> wParamMap = new HashMap<String, Object>();

            wParamMap.put("OrderID", wOrderID);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                int wPartPointID = StringUtils.parseInt(wReader.get("PartPointID"));
                wResult.put(wPartPointID, 1);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }

    /**
     * 获取台车bop导出的数据格式
     */
    public MyExcelSheet GetExportOrderBOPMyExcelSheet(List<APSTaskStep> wAPSTaskStepList) {
        MyExcelSheet wResult = new MyExcelSheet();
        try {
            wResult.HeaderList = new ArrayList<>(Arrays.asList("行号", "车型", "车号", "工区", "工位名称", "工序名称", "状态", "责任人",
                    "班组长", "专检员"));
            wResult.SheetName = "台车BOP";
            wResult.TitleName = wResult.SheetName;
            wResult.DataList = new ArrayList<>();
            int wIndex = 1;
            for (APSTaskStep wAPSTaskStep : wAPSTaskStepList) {
                List<String> wValueList = new ArrayList<>(Arrays.asList(String.valueOf(wIndex),
                        wAPSTaskStep.ProductNo, wAPSTaskStep.PartNo.split("#")[1], wAPSTaskStep.AreaName,
                        wAPSTaskStep.PartName, wAPSTaskStep.StepName, wAPSTaskStep.StatusText,
                        wAPSTaskStep.DutyPersons, wAPSTaskStep.MonitorName, wAPSTaskStep.CheckerNames));

                wResult.DataList.add(wValueList);
                wIndex++;
            }
        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    /**
     * 获取抱轴箱组装工序计划ID列表
     * 计划开始时间在今日和今日之前，状态为未推送，且已派工，且未完成
     */
    public List<Integer> APS_QueryPlanStepIDList(BMSEmployee sysAdmin, String wPlanStepIDs,
            OutResult<Integer> wErrorCode) {
        List<Integer> wResult = new ArrayList<>();
        try {
            ServiceResult<String> wInstance = this.GetDataBaseName(sysAdmin.getCompanyID(), MESDBSource.APS,
                    sysAdmin.getID(), 0);
            wErrorCode.set(wInstance.ErrorCode);
            if (wErrorCode.Result != 0) {
                return wResult;
            }

            // 获取今天的开始时间
            Calendar wToday = Calendar.getInstance();
            wToday.set(Calendar.HOUR_OF_DAY, 23);
            wToday.set(Calendar.MINUTE, 59);
            wToday.set(Calendar.SECOND, 59);

            String wSQL = StringUtils.Format("SELECT ID FROM {0}.aps_taskstep WHERE 1=1 "
                    + "and ( :StepIDs is null or :StepIDs = '''' or StepID in ({1})) "
                    + "and PlanStartTime <= :wToday " // 计划开始时间在今日及之前
                    + "and IsDispatched = 1 " // 已派工
                    + "and Status not in (5) " // 未完成
                    + "and TaskLineID != 1 " // 未推送
                    + "and Active = 1;", // 有效数据
                    wInstance.Result,
                    wPlanStepIDs);

            Map<String, Object> wParamMap = new HashMap<>();
            wParamMap.put("wToday", wToday);
            wParamMap.put("StepIDs", wPlanStepIDs);

            wSQL = this.DMLChange(wSQL);

            List<Map<String, Object>> wQueryResult = shrisJdbcTemplate.queryForList(wSQL, wParamMap);

            for (Map<String, Object> wReader : wQueryResult) {
                int wID = StringUtils.parseInt(wReader.get("ID"));
                if (wID > 0) {
                    wResult.add(wID);
                }
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
        }
        return wResult;
    }
}
